package thirdquestion;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class EmployeeManage {
    private static List<Employee> employeeList=new ArrayList<Employee>();
    static {
        employeeList.add(new Employee(1,"张三",18,3000));
        employeeList.add(new Employee(2,"李四",25,3500));
        employeeList.add(new Employee(3,"王五",22,3200));
    }

    public static void model(){
        boolean falg=false;
        for (int i = 0; i <employeeList.size() ; i++) {
            if (employeeList.get(i).getName().equals("李四")){
                Employee employee = employeeList.get(i);
                int index=employeeList.indexOf(employee);
                employeeList.set(index,new Employee(5,"赵六",24,3300));
                falg=true;
            }
        }
        if (falg){
            System.out.println("添加成功");
        }
    }
    public static void model2(){
        boolean falg=false;
        for (int i = 0; i <employeeList.size() ; i++) {
            if (employeeList.get(i).getName().equals("王五")){
                employeeList.remove(i);
                falg=true;
            }
        }
        if (falg){
            System.out.println("删除成功");
        }else {
            System.out.println("不存在这个人");
        }

    }
    public static void model3(){
        System.out.println("工号\t姓名\t年龄\t工资");
        for (Employee e:employeeList) {
            System.out.println(e.getSno()+"\t"+e.getName()+"\t"+e.getAge()+"\t"+e.getSalary());
        }
    }

    public static void model4(){
        Iterator<Employee> it=employeeList.listIterator();
        while (it.hasNext()){
            Employee employee = it.next();
            employee.work();
        }
    }
    public static void main(String[] args) {
        model();
        //model2();
        model3();
        model4();
    }

}
